/*
 * @ : Copyright (c) 2021 Phytium Information Technology, Inc. 
 *  
 * SPDX-License-Identifier: Apache-2.0.
 * 
 * @Date: 2021-07-06 08:08:20
 * @LastEditTime: 2021-09-18 15:25:17
 * @Description:  This files is for 
 * 
 * @Modify History: 
 *  Ver   Who        Date         Changes
 * ----- ------     --------    --------------------------------------
 */

#include <stdio.h>
#include "aarch32.h"

//#define EXCEPTION_DEBUG_ON
#define NO_PRINTF

void FiqDebug()
{
#ifdef EXCEPTION_DEBUG_ON
    printf("fiq abort\r\n");
#endif
}

void UdfDebug()
{
#ifdef EXCEPTION_DEBUG_ON
    printf("undefine abort\r\n");
#endif
}

void SwiDebug()
{
#ifdef EXCEPTION_DEBUG_ON
    printf("software irq abort\r\n");
#endif
}

void PrfDebug()
{
#ifdef EXCEPTION_DEBUG_ON
    printf("prefetch abort\r\n");
#endif
}

void DatDebug()
{
#ifdef EXCEPTION_DEBUG_ON
    printf("data abort\r\n");
#endif
}

extern void OutByte(s8 byte);
void TraceDebug()
{
#ifdef NO_PRINTF
    OutByte('0');
#else
    printf("stub \r\n");
#endif
}

void TraceDebug1()
{
#ifdef NO_PRINTF
    OutByte('1');
#else
    printf("stub 1\r\n");
#endif
}

void TraceDebug2()
{
#ifdef NO_PRINTF
    OutByte('2');
#else
    printf("stub 1\r\n");
#endif
}

void TraceSctrl()
{
    /* SCTLR bit :  0 --  M – Enable the MMU 
                    1 --  A – Alignment check enable 
                    2 --  C – Cache enable bit 
                    3 --  nTLSMD 
                    4 --  LSMAOE
                    5 --  CP15BEN
                    6 --  UNK
                    11 -- Z – Branch prediction enable
                    12 -- I – Instruction cache enable bit
                    13 -- V – This bit selects the base address of the exception vector table
                    16 -- nTWI 
                    18 -- nTWE, Traps EL0 execution
                    21 -- FI – FIQ configuration enable
                    22 -- U – Indicates use of the alignment model.
                    23 -- SPAN, Set Privileged Access Never
                    25 -- EE - Exception endianness
                    30 -- TE – Thumb exception enable */
    printf("MRC: 0x%lx\r\n", aarch32_sctrl_get());
}

void TraceTLB()
{
    /*
      TTBR0
    */
    printf("TLB: 0x%lx\r\n", aarch32_cntp_tlb_get());
}

void TraceR0(u32 r0)
{
    printf("r0: 0x%lx \r\n", r0);
}

void TraceR0R1(u32 r0, u32 r1)
{
    printf("r0: 0x%lx r1: 0x%lx\r\n", r0, r1);
}